#!/usr/bin/bash

key=$1
default="off"

# ARGUMENTS FOR HELP:
if [[ "" == $key ]] ; then
	echo "Error: empty param"
	bash ~/.sis/bin/sis-volume-help

	# key=$default # - default # or:
	exit `false` # close this with error
elif [[ "--help" == $key || "--version" == $key ]] ; then
	bash ~/.sis/bin/sis-volume-help $key
		
	exit `true` # close  - becose this help-run
fi

num=$2

min=30
max=70
step=10

MIN=0
MAX=100


if [[ "get" == $key ]] ; then
  return `get volume`

elif [[ "inc" == $key ]] ; then
  sis-volume + $step
elif [[ "dec" == $key ]] ; then
  sis-volume - $step

elif [[ "min" == $key ]] ; then
  sis-volume = $min
elif [[ "max" == $key ]] ; then
  sis-volume = $max

elif [[ "mute" == $key ]] ; then
    pactl set-sink-mute @DEFAULT_SINK@ toggle # off \ on

elif [[ "+" == $key ]] ; then
  sum=$(( `sis-volume get` + $num))
   
  if [[ $sum > $MAX ]] ; then
    sum=$MIN
  fi
  
  pactl set-sink-volume @DEFAULT_SINK@ +$num%
  # pactl set-sink-volume @DEFAULT_SINK@ $sum%
elif [[ "-" == $key ]] ; then
  sum=$(( `sis-volume get` - $num)) 

  if [[ $sum < $MIN ]] ; then
    sum=$MIN
  fi
  
  pactl set-sink-volume @DEFAULT_SINK@ -$num%
elif [[ "=" == $key ]] ; then
  # IF [[ $num > $MAX ]] ; THEN
  #	 num=$MAX
  # FLIF [[ $num < $MIN ]] ; THEN
  #	 num=$MIN
  # FI
  
  pactl set-sink-volume @DEFAULT_SINK@ $num%
else
     exit `false`
fi

